GtkStyleContext: add some aux. a11y api
authorMatthias Clasen <mclasen@redhat.com>
Sat, 25 Jun 2011 00:26:42 +0000 (20:26 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 5 Jul 2011 20:08:07 +0000 (16:08 -0400)
This function translates the fg/bg color into atk attributes.

gtk/gtkstylecontext.c
gtk/gtkstylecontext.h

index 93a3defb2f7cd2a2c1654abed81e4f773cfb6eb8..d63d35bac45232f11be0934a2361d94b6feb4ce2 100644 (file)
@@ -4313,3 +4313,58 @@ gtk_render_icon (GtkStyleContext *context,
 
   cairo_restore (cr);  
 }
+
+static AtkAttributeSet *
+add_attribute (AtkAttributeSet  *attributes,
+               AtkTextAttribute  attr,
+               const gchar      *value)
+{
+  AtkAttribute *at;
+
+  at = g_new (AtkAttribute, 1);
+  at->name = g_strdup (atk_text_attribute_get_name (attr));
+  at->value = g_strdup (value);
+
+  return g_slist_prepend (attributes, at);
+}
+
+/*
+ * _gtk_style_context_get_attributes:
+ * @attributes: a #AtkAttributeSet to add attributes to
+ * @context: the #GtkStyleContext to get attributes from
+ * @flags: the state to use with @context
+ *
+ * Adds the foreground and background color from @context to
+ * @attributes, after translating them to ATK attributes.
+ *
+ * This is a convenience function that can be used in
+ * implementing the #AtkText interface in widgets.
+ *
+ * Returns: the modified #AtkAttributeSet
+ */
+AtkAttributeSet *
+_gtk_style_context_get_attributes (AtkAttributeSet *attributes,
+                                   GtkStyleContext *context,
+                                   GtkStateFlags    flags)
+{
+  GdkRGBA color;
+  gchar *value;
+
+  gtk_style_context_get_background_color (context, flags, &color);
+  value = g_strdup_printf ("%u,%u,%u",
+                           (guint) ceil (color.red * 65536 - color.red),
+                           (guint) ceil (color.green * 65536 - color.green),
+                           (guint) ceil (color.blue * 65536 - color.blue));
+  attributes = add_attribute (attributes, ATK_TEXT_ATTR_BG_COLOR, value);
+  g_free (value);
+
+  gtk_style_context_get_color (context, flags, &color);
+  value = g_strdup_printf ("%u,%u,%u",
+                           (guint) ceil (color.red * 65536 - color.red),
+                           (guint) ceil (color.green * 65536 - color.green),
+                           (guint) ceil (color.blue * 65536 - color.blue));
+  attributes = add_attribute (attributes, ATK_TEXT_ATTR_FG_COLOR, value);
+  g_free (value);
+
+  return attributes;
+}
index 661edd0f764ecfe8a840b2c98e970e58adcf1a01..dd1339508cb3595a5dd2a14ad5fedbc8281ff660 100644 (file)
@@ -28,6 +28,7 @@
 #include <gtk/gtkstyleprovider.h>
 #include <gtk/gtkwidgetpath.h>
 #include <gtk/gtkborder.h>
+#include <atk/atk.h>
 
 G_BEGIN_DECLS
 
@@ -858,6 +859,11 @@ void        gtk_render_icon        (GtkStyleContext     *context,
                                     gdouble              x,
                                     gdouble              y);
 
+/* Accessibility support */
+AtkAttributeSet *_gtk_style_context_get_attributes (AtkAttributeSet *attributes,
+                                                    GtkStyleContext *context,
+                                                    GtkStateFlags    flags);
+
 G_END_DECLS
 
 #endif /* __GTK_STYLE_CONTEXT_H__ */